--时停秒杀
AddModRPCHandler("mymod", "root_target", function(inst)
    if not inst:HasTag("playerghost") and inst.components.health ~= nil and inst.components.health.currenthealth > 0 then
        local exclude_tags = { "INLIMBO", "companion", "wall", "abigail", "shadowminion" } ---屏幕内，朋友，墙，阿比盖尔，暗影随从
        local x2, y2, z2 = inst.Transform:GetWorldPosition()
        local ents = TheSim:FindEntities(x2, y2, z2, 30, { "_combat" }, exclude_tags)
        --进行播报
        inst.components.talker:Say("开始清算")
        -- 遍历找到的实体
        for i, ent in ipairs(ents) do
            if ent ~= inst then
                if not ent:HasTag("root_target") and ent.components.health ~= nil and ent.components.health.currenthealth > 0 then
                    -----------------------------------------------
                    ent:AddTag("root_target")
                    ent:StopBrain()
                    if ent.sg then
                        ent.sg:Stop()
                    end
                    if ent.Physics then
                        ent.Physics:SetActive(false)
                    end
                    if ent.AnimState then
                        ent.AnimState:Pause()
                    end
                    -----------------------------------------------
                    ent:DoTaskInTime(1, function()
                        if ent:HasTag("root_target") then
                            ent:RemoveTag("root_target")
                            ent:RestartBrain()
                            if ent.sg then
                                ent.sg:Start()
                                --ent.sg:GoToState("hit")
                                --ent:PushEvent("attacked", { attacker = owner, damage = 0 })
                                -- ent.AnimState:PlayAnimation("hit")
                            end
                            if ent.Physics then
                                ent.Physics:SetActive(true)
                            end
                            if ent.AnimState then
                                ent.AnimState:Resume()
                            end
                            --ent.AnimState:PlayAnimation("disappear")
                            ---------------------------------------------------------
                            ent.components.health:Kill()
                        end
                    end)
                end
            end
        end
    end
end)

--[[
ent:AddComponent("rooted")
                ent:AddTag("rooted")
                local fx = SpawnPrefab("heartfx") -- 生成一个特效
                fx.entity:SetParent(ent.entity)          -- 设置成跟随玩家
                --ent.AnimState:SetErosionParams(0, 0, 0)
                --ent.AnimState:SetMultColour(255/255, 185/255, 15, 1)
                    --ent.AnimState:SetErosionParams(0, 0.5, -1)
                ]]

GLOBAL.TheInput:AddKeyHandler(function(key, down) -- 监听键盘事件
    if down and key == GLOBAL.KEY_R then
        SendModRPCToServer(MOD_RPC["memod"]["root_target"])
    end
end)
